package com.escool.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.escool.model.TbTipoRecord;
@Repository
public class TipoRecordDAOImpl implements TipoRecordDAO {
	
	@Autowired
	SessionFactory sessionFactory;

	@Override
	public void add(TbTipoRecord dao) {
		sessionFactory.getCurrentSession().save(dao);

	}

	@Override
	public void edit(TbTipoRecord dao) {
		sessionFactory.getCurrentSession().update(dao);

	}

	@Override
	public List<TbTipoRecord> listAll() {
		
		return sessionFactory.getCurrentSession().createQuery("from TbTipoRecord").list();
	}

	@Override
	public void delete(Integer id) {
		TbTipoRecord dao = (TbTipoRecord) sessionFactory.getCurrentSession().load(TbTipoRecord.class, id);
		if (dao != null){
			sessionFactory.getCurrentSession().delete(dao);
		}

	}

	@Override
	public TbTipoRecord findById(Integer id) {
		// TODO Auto-generated method stub
		return (TbTipoRecord) sessionFactory.getCurrentSession().get(TbTipoRecord.class, id);
	}

}
